package com.sinosoft.product;

public class DataQueryModelSet {
	public static DataQueryModel getQueryModel(String ltlong, String rBlong,
			String lTlat, String rBlat, String productSelect, String page,
			String imagegsd, String scenedatestart, String scenedateend,
			String cloudpercent, String overalldataquality, String sateAndsensor,String national,String province,String county) {
		DataQueryModel datamod = new DataQueryModel();
		datamod.setLeftTlong(ltlong);// "41"
		datamod.setRightBlong(rBlong);// "83"
		datamod.setLeftTlat(lTlat);// "40"
		datamod.setRightBlat(rBlat);// "87"
		datamod
				.setProductlevel("0".equalsIgnoreCase(productSelect) ? "0_PRODUCT"
						: productSelect);
		datamod.setPage(page);
		datamod.setImagegsd(imagegsd);
		datamod.setScenedatestart(scenedatestart);
		datamod.setScenedateend(scenedateend);
		datamod.setCloudpercent(cloudpercent);
		datamod.setOveralldataquality(overalldataquality);
		datamod.setSateAndsensor(sateAndsensor);
		datamod.setNationalid(national);
		datamod.setProvinceid(province);
		datamod.setCountyid(county);
		return datamod;
	}

	public static String getSql(DataQueryModel datamodel) {
		StringBuffer sql = new StringBuffer();
		// and t.IMAGEGSD = '"+datamodel.getImagegsd()+"'
		// and t. cloudpercent ='"+datamodel.getCloudpercent()+"'
		// and t.OVERALLDATAQUALITY = '"+datamodel.getOveralldataquality()+"'
		// and t.scenedate > to_date('2001-01-01', 'yyyy/MM/DD')
		// and t.scenedate < to_date('2012-01-01', 'yyyy/MM/DD')
		sql.append("".equalsIgnoreCase(datamodel.getImagegsd()) ? ""
				: " and t.IMAGEGSD < = " + datamodel.getImagegsd());
		sql.append("".equalsIgnoreCase(datamodel.getCloudpercent()) ? ""
				: " and t.cloudpercent < = " + datamodel.getCloudpercent());
		sql.append("".equalsIgnoreCase(datamodel.getOveralldataquality()) ? ""
				: " and t.OVERALLDATAQUALITY  > = "
						+ datamodel.getOveralldataquality());
		sql.append("".equalsIgnoreCase(datamodel.getScenedatestart()) ? ""
				: " and t.scenedate > = to_date('"
						+ datamodel.getScenedatestart() + "', 'yyyy/MM/DD')");

		sql.append("".equalsIgnoreCase(datamodel.getScenedateend()) ? ""
				: " and t.scenedate -1 < =  to_date('"
						+ datamodel.getScenedateend() + "', 'yyyy/MM/DD')");

		return sql.toString();

	}

	public static String getSateAndSensor(String satellites) {
		StringBuffer sql = new StringBuffer();
		sql.append(" and ( ");
		if ("".equalsIgnoreCase(satellites)) {
			sql.append(" 1=1 )");
		} else {
			String[] str = satellites.split(",");
			for (int i = 0; i < str.length; i++) {
				String sqlstr = "( t.satelliteid = '" + str[i].split("_")[0]
						+ "' and t.sensorid = '" + str[i].split("_")[1] + "' )";
				if (str.length == (i + 1)) {
					sql.append(sqlstr + ")");
				} else {
					sql.append(sqlstr + " or");
				}

			}
		}
		return sql.toString();
	}
}
